package inet.app.view.activity;

import inet.app.R;
import inet.app.controller.connect.JsonParser;
import inet.app.model.object.TkdateItem;
import inet.app.model.util.Util;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Random;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

/*public class DudoanActivity extends BaseActivity implements
 OnCheckedChangeListener, OnKeyListener*/
public class DudoanActivity extends BaseFragmentActivity implements
		OnCheckedChangeListener, OnKeyListener {
	Random ran;
	TextView tvsochon, tvsochon1, tvsochon2, tvsochon3, tvsochon4, tvsochon5,
			tvsochon6, tvsochon7, tvsochon8, tvsochon9, tvsochon10;
	TextView tvluotchon, tvluotchon1, tvluotchon2, tvluotchon3, tvluotchon4,
			tvluotchon5, tvluotchon6, tvluotchon7, tvluotchon8, tvluotchon9,
			tvluotchon10;
	TextView tvfotter, tvtyle, tvtyle1, tvtyle2, tvtyle3, tvtyle4, tvtyle5,
			tvtyle6, tvtyle7, tvtyle8, tvtyle9, tvtyle10;
	Dialog dialog;
	RadioButton radioall, radiodb;
	Dialog help;
	String bovenhieu, boveit, name, matinh;
	String strMax[];
	String strMin[];
	JSONObject json;
	String sotatus;
	int count = 0;
	int giaichon = 30;
	Handler hl, hl1;
	String capso;
	Runnable run, run1;
	int demtrang = 1;
	int max = 10;
	int luotdudoan, tyle;
	boolean quay, quay1; // Bien nay xac dinh co' cho so' quay hay ko
	boolean key;
	int kq, de, kqde;
	int kqdb, kq11, kq12, kq21, kq22, kq23, kq24, kq31, kq32, kq33, kq34, kq35;
	int kq41, kq42, kq43, kq44, kq45, kq46, kq51, kq52, kq53, kq54, kq61, kq62,
			kq63, kq71, kq72, kq73, kq74, kq81;
	int randomNumber;
	EditText etsode, etchonso;
	Button btmayman, btguikq, btxemkq;
	TextView tvmessage, tvthongbao, tvTitle;
	//
	private static String url = "http://appsrv.sms.vn/app/Xoso?action=gettkdate";
	// JSON Node names
	private static final String TAG_ACTION = "ACTION";
	private static final String TAG_STATUS = "STATUS";
	private static final String TAG_DESC = "DESC";
	private static final String TAG_CODE = "CODE";
	private static final String TAG_NAME = "NAME";
	private static final String TAG_NUMBERDATE = "NUMBERDATE";
	private static final String TAG_RESULTMAX = "RESULT_MAX";
	private static final String TAG_RESULTMIN = "RESULT_MIN";

	// contacts JSONArray
	JSONArray LIST = null;

	JSONArray contacts = null;
	// ----------------------------------------------------
	// Button btKQXSSelect,btKQXSSearch;
	TextView tvmin, tvmax;
	Button btsoicau, btquay, btdung;
	TextView tvketqualoto, tvxemngaytruoc, tvtkloto, tvtime, tvdbtrue8;
	Typeface tf;
	Dialog about;
	Random random;
	List<String> listrandom = new ArrayList<String>();
	// thêm mới
	List<String> listresultmax = new ArrayList<String>();
	List<String> listresultmin = new ArrayList<String>();

	ArrayAdapter<TkdateItem> adapter;
	ArrayList<TkdateItem> items;
	private ListView list;

	Thread timer, timer1;
	int orange = Color.rgb(255, 150, 0);
	int blue = Color.rgb(0, 150, 255);
	int Green1 = Color.rgb(0, 255, 0);
	int Yellow1 = Color.rgb(255, 255, 0);
	int Red1 = Color.rgb(255, 0, 0);
	int heavyblue = Color.rgb(0, 0, 255);
	Spinner spSearchDiadiem;
	SharedPreferences data;
	int searchtype;
	int selectedPeriod;
	SharedPreferences.Editor editor;
	public static final String filename = "TimePeriod";

	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.dudoan_screen);
		initBase();
		initUI();
		implementUI();

	}

	private void initUI() {
		// TODO Auto-generated method stub
		tvfotter = (TextView) findViewById(R.id.tvfotter);
		tvTitle = (TextView) findViewById(R.id.tvTitle);
		tvTitle.setText("Dự Đoán");
		final Animation text_animation = AnimationUtils.loadAnimation(this,
				R.anim.custom_text_animation);
		tvfotter.startAnimation(text_animation);

		tvfotter.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent myWebLink = new Intent(
						android.content.Intent.ACTION_VIEW);
				myWebLink.setData(Uri.parse("http://m.ole.vn/"));
				startActivity(myWebLink);
			}
		});
		tvsochon = (TextView) findViewById(R.id.tvsochon);
		tvsochon1 = (TextView) findViewById(R.id.tvsochon1);
		tvsochon2 = (TextView) findViewById(R.id.tvsochon2);
		tvsochon3 = (TextView) findViewById(R.id.tvsochon3);
		tvsochon4 = (TextView) findViewById(R.id.tvsochon4);
		tvsochon5 = (TextView) findViewById(R.id.tvsochon5);
		tvsochon6 = (TextView) findViewById(R.id.tvsochon6);
		tvsochon7 = (TextView) findViewById(R.id.tvsochon7);
		tvsochon8 = (TextView) findViewById(R.id.tvsochon8);
		tvsochon9 = (TextView) findViewById(R.id.tvsochon9);
		tvsochon10 = (TextView) findViewById(R.id.tvsochon10);

		tvluotchon = (TextView) findViewById(R.id.tvluotchon);
		tvluotchon1 = (TextView) findViewById(R.id.tvluotchon1);
		tvluotchon2 = (TextView) findViewById(R.id.tvluotchon2);
		tvluotchon3 = (TextView) findViewById(R.id.tvluotchon3);
		tvluotchon4 = (TextView) findViewById(R.id.tvluotchon4);
		tvluotchon5 = (TextView) findViewById(R.id.tvluotchon5);
		tvluotchon6 = (TextView) findViewById(R.id.tvluotchon6);
		tvluotchon7 = (TextView) findViewById(R.id.tvluotchon7);
		tvluotchon8 = (TextView) findViewById(R.id.tvluotchon8);
		tvluotchon9 = (TextView) findViewById(R.id.tvluotchon9);
		tvluotchon10 = (TextView) findViewById(R.id.tvluotchon10);

		tvtyle = (TextView) findViewById(R.id.tvtyle);
		tvtyle1 = (TextView) findViewById(R.id.tvtyle1);
		tvtyle2 = (TextView) findViewById(R.id.tvtyle2);
		tvtyle3 = (TextView) findViewById(R.id.tvtyle3);
		tvtyle4 = (TextView) findViewById(R.id.tvtyle4);
		tvtyle5 = (TextView) findViewById(R.id.tvtyle5);
		tvtyle6 = (TextView) findViewById(R.id.tvtyle6);
		tvtyle7 = (TextView) findViewById(R.id.tvtyle7);
		tvtyle8 = (TextView) findViewById(R.id.tvtyle8);
		tvtyle9 = (TextView) findViewById(R.id.tvtyle9);
		tvtyle10 = (TextView) findViewById(R.id.tvtyle10);

		etchonso = (EditText) findViewById(R.id.etchonso);
		capso = etchonso.getText().toString();
		tvmessage = (TextView) findViewById(R.id.tvmessage);
		tvthongbao = (TextView) findViewById(R.id.tvthongbao);
		btguikq = (Button) findViewById(R.id.btguikq);
		btxemkq = (Button) findViewById(R.id.btxemkq);
		tvthongbao.setText(null);
		tvmessage.setText(null);
		btguikq.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub

				count++;
				if (capso.equals("") == true) {
					Toast.makeText(DudoanActivity.this,
							"Bạn chưa nhập số dự đoán !", Toast.LENGTH_SHORT)
							.show();
				} else {
					tvsochon.setText("");
					tvsochon1.setText("");
					tvsochon2.setText("");
					tvsochon3.setText("");
					tvsochon4.setText("");
					tvsochon5.setText("");
					tvsochon6.setText("");
					tvsochon7.setText("");
					tvsochon8.setText("");
					tvsochon9.setText("");
					tvsochon10.setText("");
					// ///////////////////
					tvluotchon.setText("");
					tvluotchon1.setText("");
					tvluotchon2.setText("");
					tvluotchon3.setText("");
					tvluotchon4.setText("");
					tvluotchon5.setText("");
					tvluotchon6.setText("");
					tvluotchon7.setText("");
					tvluotchon8.setText("");
					tvluotchon9.setText("");
					tvluotchon10.setText("");

					tvtyle.setText("");
					tvtyle1.setText("");
					tvtyle2.setText("");
					tvtyle3.setText("");
					tvtyle4.setText("");
					tvtyle5.setText("");
					tvtyle6.setText("");
					tvtyle7.setText("");
					tvtyle8.setText("");
					tvtyle9.setText("");
					tvtyle10.setText("");
					tvmessage.setText("  Gửi chọn số thành công!");
					tvthongbao.setText("   Số người cùng chọn số " + capso
							+ " là: " + (luotdudoan + count) + " Tỷ lệ: "
							+ tyle + " %");
				}
			}
		});
		btxemkq.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				tvmessage.setText("  10 số được lựa chọn nhiều nhất");
				tvmessage.setTextColor(heavyblue);
				tvthongbao.setTextColor(Red1);
				tvthongbao.setText("   Xổ Số Miền Bắc ");
				setdata();
			}
		});
		etchonso.setOnKeyListener(this);
		radioall = (RadioButton) findViewById(R.id.radioall);
		radiodb = (RadioButton) findViewById(R.id.radiodb);
		radioall.setOnKeyListener(this);

		radioall.setOnCheckedChangeListener(DudoanActivity.this);
		radioall.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				radioall.setChecked(true);
				radiodb.setChecked(false);
			}
		});
		radiodb.setOnCheckedChangeListener(DudoanActivity.this);
		radiodb.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				radiodb.setChecked(true);
				radioall.setChecked(false);
			}
		});
		tf = Typeface.createFromAsset(getAssets(), "fonts/myFont.TTF");
		searchtype = 0;
		btquay = (Button) findViewById(R.id.btquay);
		btdung = (Button) findViewById(R.id.btdung);
		spSearchDiadiem = (Spinner) findViewById(R.id.spSearchDiadiem);

		String[] loaitimkiem = new String[] { "Thủ Đô", "TP HCM", "An Giang",
				"Bình Dương", "Bình Phước", "Bạc Liêu", "Bến Tre", "Cà Mau",
				"Cần Thơ", "Hậu Giang", "Kiên Giang", "Long An", "Sóc Trăng",
				"Tiền Giang", "Trà Vinh", "Tây Ninh", "Vĩnh Long", "Vũng Tàu",
				"Đà Lạt", "Đồng Nai", "Đồng Tháp", "Bình Thuận", "Bình Định",
				"Đắk Lắk", "Gia Lai", "Khánh Hòa", "Kon Tum", "Ninh Thuận",
				"Phú Yên", "Quảng Bình", "Quảng Nam", "Quảng Ngãi",
				"Quảng Trị", "Thừa Thiên Huế", "Đà Nẵng", "Đắc Nông" };
		ArrayAdapter<String> loaitkadapter = new ArrayAdapter<String>(
				DudoanActivity.this, android.R.layout.simple_spinner_item,
				loaitimkiem);
		loaitkadapter
				.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spSearchDiadiem.setAdapter(loaitkadapter);
		spSearchDiadiem
				.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

					public void onItemSelected(AdapterView<?> arg0, View v,
							int pos, long id) {
						switch (pos) {
						case 0:
							searchtype = 0;
							name = "Thủ Đô";
							matinh = "XSTD";
							onResume();
							break;
						case 1:
							searchtype = 1;
							name = "TP HCM";
							matinh = "XSHCM";
							break;
						case 2:
							searchtype = 2;
							matinh = "XSAG";
							name = "An Giang";
							break;
						case 3:
							searchtype = 3;
							matinh = "XSBD";
							name = "Bình Dương";
							break;
						case 4:
							searchtype = 4;
							matinh = "XSBP";
							name = "Bình Phước";
							break;
						case 5:
							searchtype = 5;
							matinh = "XSBL";
							name = "Bạc Liêu";
							break;
						case 6:
							searchtype = 6;
							matinh = "XSBT";
							name = "Bến Tre";
							break;
						case 7:
							searchtype = 7;
							matinh = "XSCM";
							name = "Cà Mau";
							break;
						case 8:
							searchtype = 8;
							matinh = "XSCT";
							name = "Cần Thơ";
							break;
						case 9:
							searchtype = 9;
							matinh = "XSHG";
							name = "Hậu Giang";
							break;
						case 10:
							searchtype = 10;
							matinh = "XSKG";
							name = "Kiên Giang";
							break;
						case 11:
							searchtype = 11;
							matinh = "XSLA";
							name = "Long An";
							break;
						case 12:
							searchtype = 12;
							matinh = "XSST";
							name = "Sóc Trăng";
							break;
						case 13:
							searchtype = 13;
							matinh = "XSTG";
							name = "Tiền Giang";
							break;
						case 14:
							searchtype = 14;
							matinh = "XSTV";
							name = "Trà Vinh";
							break;
						case 15:
							searchtype = 15;
							matinh = "XSTN";
							name = "Tây Ninh";
							break;
						case 16:
							searchtype = 16;
							matinh = "XSVL";
							name = "Vĩnh Long";
							break;
						case 17:
							searchtype = 17;
							matinh = "XSVT";
							name = "Vũng Tàu";
							break;
						case 18:
							searchtype = 18;
							matinh = "XSDL";
							name = "Đà Lạt";
							break;
						case 19:
							searchtype = 19;
							matinh = "XSDN";
							name = "Đông Nai";
							break;
						case 20:
							searchtype = 20;
							matinh = "XSDT";
							name = "Đồng Tháp";
							break;
						case 21:
							searchtype = 21;
							matinh = "XSBTH";
							name = "Bình Thuận";
							break;
						case 22:
							searchtype = 22;
							matinh = "XSBDH";
							name = "Bình Định";
							break;
						case 23:
							searchtype = 23;
							matinh = "XSDLK";
							name = "Đăk Lăk";
							break;
						case 24:
							searchtype = 24;
							matinh = "XSGL";
							name = "Gia Lai";
							break;
						case 25:
							searchtype = 25;
							matinh = "XSKH";
							name = "Khánh Hòa";
							break;
						case 26:
							searchtype = 26;
							matinh = "XSKT";
							name = "Kon Tum";
							break;
						case 27:
							searchtype = 27;
							matinh = "XSNT";
							name = "Ninh Thuận";
							break;
						case 28:
							searchtype = 28;
							matinh = "XSPY";
							name = "Phú Yên";
							break;

						case 29:
							searchtype = 29;
							matinh = "XSQB";
							name = "Quảng Bình";
							break;
						case 30:
							searchtype = 30;
							matinh = "XSQNM";
							name = "Quảng Nam";
							break;
						case 31:
							searchtype = 31;
							matinh = "XSQNI";
							name = "Quảng Ngãi";
							break;
						case 32:
							searchtype = 32;
							matinh = "XSQT";
							name = "Quảng Trị";
							break;
						case 33:
							searchtype = 33;
							matinh = "XSTTH";
							name = "Thừa Thiên Huế";
							break;
						case 34:
							searchtype = 34;
							matinh = "XSDNG";
							name = "Đà Nẵng";
							break;
						case 35:
							searchtype = 35;
							matinh = "XSDNO";
							name = "Đắc Nông";
							break;

						}
					}

					public void onNothingSelected(AdapterView<?> arg0) {
					}
				});

		// de=-1; // Khong phai quan tam den cai nay nghich thoi
		ran = new Random(); // Khoi tao bien Random

		luotdudoan = 100 + ran.nextInt(899);
		tyle = luotdudoan / 17;

		tvsochon.setText("");
		tvsochon1.setText("");
		tvsochon2.setText("");
		tvsochon3.setText("");
		tvsochon4.setText("");
		tvsochon5.setText("");
		tvsochon6.setText("");
		tvsochon7.setText("");
		tvsochon8.setText("");
		tvsochon9.setText("");
		tvsochon10.setText("");
		// ///////////////////
		tvluotchon.setText("");
		tvluotchon1.setText("");
		tvluotchon2.setText("");
		tvluotchon3.setText("");
		tvluotchon4.setText("");
		tvluotchon5.setText("");
		tvluotchon6.setText("");
		tvluotchon7.setText("");
		tvluotchon8.setText("");
		tvluotchon9.setText("");
		tvluotchon10.setText("");

		tvtyle.setText("");
		tvtyle1.setText("");
		tvtyle2.setText("");
		tvtyle3.setText("");
		tvtyle4.setText("");
		tvtyle5.setText("");
		tvtyle6.setText("");
		tvtyle7.setText("");
		tvtyle8.setText("");
		tvtyle9.setText("");
		tvtyle10.setText("");

	}

	private void implementUI() {
		// TODO Auto-generated method stub

	}

	private void setdata() {
		// lấy dữ liệu trả về từ trang trước
		String urlfotter = "&code=" + matinh + "&numberdate=" + giaichon;
		// TODO Auto-generated method stub
		// Hashmap for ListView
		Calendar cal = Calendar.getInstance();
		// ////////-----------------------------
		ArrayList<HashMap<String, String>> contactList = new ArrayList<HashMap<String, String>>();

		// Creating JSON Parser instance
		JsonParser jParser = new JsonParser();

		// getting JSON string from URL
		json = jParser.getJSONFromUrl(url + urlfotter);
		if (json == null) {
			Util.showDialog(1, DudoanActivity.this);
		} else {
			try {
				// Getting Array of Contacts
				bovenhieu = json.getString(TAG_RESULTMAX);
			} catch (JSONException ex) {
				ex.printStackTrace();
			}

			System.out.println("du lieu tra ve" + bovenhieu + boveit);
			try {
				sotatus = json.getString(TAG_ACTION);
				name = json.getString(TAG_NAME);
				boveit = json.getString(TAG_RESULTMIN);
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			// System.out.println("chet mat thoi"+sotatus+name+ boveit);

			strMax = bovenhieu.split(";");
			strMin = boveit.split(";");
			System.out.println("phan tu thu 1 là " + strMax[1]);

			tvsochon.setText("        Số chọn");
			tvsochon1.setText(strMax[0].substring(0, 2));
			tvsochon2.setText(strMax[1].substring(0, 2));
			tvsochon3.setText(strMax[2].substring(0, 2));
			tvsochon4.setText(strMax[3].substring(0, 2));
			tvsochon5.setText(strMax[4].substring(0, 2));
			tvsochon6.setText(strMax[5].substring(0, 2));
			tvsochon7.setText(strMax[6].substring(0, 2));
			tvsochon8.setText(strMax[7].substring(0, 2));
			tvsochon9.setText(strMax[8].substring(0, 2));
			tvsochon10.setText(strMax[9].substring(0, 2));
			// /////////////////////
			tvluotchon.setText("Lượt chọn");
			tvluotchon1.setText(strMax[0].substring(3, strMax[0].length())
					+ " lượt");
			tvluotchon2.setText(strMax[1].substring(3, strMax[1].length())
					+ " lượt");
			tvluotchon3.setText(strMax[2].substring(3, strMax[2].length())
					+ " lượt");
			tvluotchon4.setText(strMax[3].substring(3, strMax[3].length())
					+ " lượt");
			tvluotchon5.setText(strMax[4].substring(3, strMax[4].length())
					+ " lượt");
			tvluotchon6.setText(strMax[5].substring(3, strMax[5].length())
					+ " lượt");
			tvluotchon7.setText(strMax[6].substring(3, strMax[6].length())
					+ " lượt");
			tvluotchon8.setText(strMax[7].substring(3, strMax[7].length())
					+ " lượt");
			tvluotchon9.setText(strMax[8].substring(3, strMax[8].length())
					+ " lượt");
			tvluotchon10.setText(strMax[9].substring(3, strMax[9].length())
					+ " lượt");

			tvtyle.setText("Tỷ lệ chọn");
			tvtyle1.setText(""
					+ Integer.parseInt(strMax[0].substring(3,
							strMax[0].length())) / 2.5 + " %");
			tvtyle2.setText(""
					+ Integer.parseInt(strMax[1].substring(3,
							strMax[1].length())) / 2.5 + " %");
			tvtyle3.setText(""
					+ Integer.parseInt(strMax[2].substring(3,
							strMax[2].length())) / 2.5 + " %");
			tvtyle4.setText(""
					+ Integer.parseInt(strMax[3].substring(3,
							strMax[3].length())) / 2.5 + " %");
			tvtyle5.setText(""
					+ Integer.parseInt(strMax[4].substring(3,
							strMax[4].length())) / 2.5 + " %");
			tvtyle6.setText(""
					+ Integer.parseInt(strMax[5].substring(3,
							strMax[5].length())) / 2.5 + " %");
			tvtyle7.setText(""
					+ Integer.parseInt(strMax[6].substring(3,
							strMax[6].length())) / 2.5 + " %");
			tvtyle8.setText(""
					+ Integer.parseInt(strMax[7].substring(3,
							strMax[7].length())) / 2.5 + " %");
			tvtyle9.setText(""
					+ Integer.parseInt(strMax[8].substring(3,
							strMax[8].length())) / 2.5 + " %");
			tvtyle10.setText(""
					+ Integer.parseInt(strMax[9].substring(3,
							strMax[9].length())) / 2.5 + " %");
		}
	}

	@Override
	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		// TODO Auto-generated method stub
		switch (buttonView.getId()) {
		case R.id.radioall:
			giaichon = 10;

			luotdudoan = 10 + ran.nextInt(89);
			tyle = (luotdudoan + count) / 17;
			break;
		case R.id.radiodb:
			giaichon = 30;
			luotdudoan = 100 + ran.nextInt(899);
			tyle = (luotdudoan + count) / 17;
			break;
		default:
			break;
		}

	}

	@Override
	public boolean onKey(View v, int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub

		switch (v.getId()) {
		case R.id.etchonso:
			capso = etchonso.getText().toString();
			// kqde=Integer.parseInt(capso);
			break;
		case R.id.radioall:
			// giaichon=30;
			break;
		default:
			break;
		}
		return false;
	}

	private void showRandomInteger(int aStart, int aEnd, Random aRandom) {
		if (aStart > aEnd) {
			throw new IllegalArgumentException("Start cannot exceed End.");
		}
		// get the range, casting to long to avoid overflow problems
		long range = (long) aEnd - (long) aStart + 1;
		long fraction = (long) (range * aRandom.nextDouble());
		randomNumber = (int) (fraction + aStart);
		log("Generated : " + randomNumber);
		listrandom.add(Integer.toString(randomNumber));
	}

	private static void log(String aMessage) {
		System.out.println(aMessage);
	}

	public void onBackPressed() {
		finish();
		return;
	}

	public void aboutDialog(Context c) {
		about = new Dialog(c);
		about.setTitle("              Thông Tin");
		about.setContentView(R.layout.dialog_about);
		Button dong = (Button) about.findViewById(R.id.btAboutClose);
		dong.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				about.dismiss();
			}
		});
	}

	public void showProgressDialog(Activity act) {
		if (dialog == null) {
			dialog = ProgressDialog.show(act, "", "Đang tải...", true, true);
			Thread progress = new Thread() {
				@Override
				public void run() {
					while (((MyApp) getApplication()).isCanNext() == false) {
					}

					if (((MyApp) getApplication()).isCanNext() == true) {
						dialog.dismiss();
					}
				}
			};
			progress.start();
		} else if (!dialog.isShowing()) {
			dialog = ProgressDialog.show(act, "", "Đang tải...", true, true);
			Thread progress = new Thread() {
				@Override
				public void run() {
					while (((MyApp) getApplication()).isCanNext() == false) {
					}

					if (((MyApp) getApplication()).isCanNext() == true) {
						dialog.dismiss();

					}
				}
			};
			progress.start();
		}

	}

	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			System.out.println("THOAT NHE");
			showQuitDialog(DudoanActivity.this);
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}

	@Override
	public void onResume() {
		// TODO Auto-generated method stub
		if (((MyApp) getApplication()).isKill()) {
			finish();
		}
		super.onResume();

	}
}
